package cc.wsyw126.java.lambda;

import cc.wsyw126.java.model.User;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by junpeng.yang on 16/9/18.
 */
public class CreateMap {
    public static void main(String[] args) {
        List<User> users = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            User user = new User();
            user.setName(""+i);
            user.setPassword(""+i);
            users.add(user);
        }

//        Map<String,Long> result = users.stream().collect(Collectors.groupingBy(User::getName,Collectors.counting()));
        Map<String,List<User>> result = users.stream().collect(Collectors.groupingBy(User::getName));

        Iterator iterator = result.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry entry = (Map.Entry<String,List<User>>)iterator.next();
            System.out.println("Key : " + entry.getKey());

            List u = (List<User>) entry.getValue();
            u.forEach(element-> System.out.println("element : " + element));
        }

    }
}
